javascript check if variable exists

99

check if isset variable js -

var status = 'Variable exists'

try {
  myVar
} catch (ReferenceError) {
  status = 'Variable does not exist'
}

console.log(status)

if variable does not exist javascript -

if (typeof variable === 'undefined') {
    // variable is undefined
    // eg:
    // var variable = "someValue";
}

Comments

Submit
0 Comments